package thefirst.mypage.model;

import java.util.List;

import javax.annotation.Resource;

import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.stereotype.Repository;

import thefirst.member.model.MemberVO;
@Repository
public class TeacherLessonListDaoImpl implements SelectedListDao {
	@Resource(name="sqlSessionTemplate")
	private SqlSessionTemplate sqlSessionTemplate;
	
	/**
	 * 선생님이 찜한 과외 수업
	 * 학생이 등록한 과외수업을 찜한 선생님
	 */
	@Override
	public List<SelectedListVO> showSelectedListVO(MemberVO mvo)
			throws Exception {
		if(mvo.getMembertype().equals("s")){// 학생이 로그인 되어 있으면 
			//if a student is logged, 
			return sqlSessionTemplate.selectList
						("selectedList.showClassTeacherListVO",mvo);
			//수업을 찜한 선생님 리스트
			//Returns a list of selected teachers
		}
		// nor Returns a list of students who select the teacher
		System.out.println("showSelectedListVO : showStudentListVO"+mvo);
			return sqlSessionTemplate.selectList
						("selectedList.showLessonStudentListVO",mvo);
	}

	@Override
	public int countMember_st(MemberVO mvo) throws Exception {
		// TODO Auto-generated method stub
		if(mvo.getMembertype().equals("s")){// 학생이 로그인 되어 있으면 
			return sqlSessionTemplate.selectOne("selectedList.countTeacher_st",mvo);
		}
		System.out.println("countMember_st: "+mvo.getMembertype());
		return sqlSessionTemplate.selectOne("selectedList.countStudent_st",mvo);
	}

	@Override
	public void registerSelectedListVO(SelectedListVO slvo) throws Exception {
		// TODO Auto-generated method stub
		System.out.println("dao> registerSelectedListVO"+slvo);
		sqlSessionTemplate.insert
		("selectedList.registerSelectedListVOinTeacherlessonList", slvo);
	}
	
	public List getSelectedList(String id) throws Exception{
		return sqlSessionTemplate.selectList("selectedList.getLessonnoList", id);
	}

	@Override
	public void deleteSelectedListVO(String id) throws Exception {
		// TODO Auto-generated method stub
		 sqlSessionTemplate.delete("selectedList.deleteSelectedLesson", id);
	}
}
